
<template>
  <!-- 单词本 -->
  <div>
    <Header :width="1000"></Header>
    <div class="word-book sentence-book w1000">
      <div class="word-book-container">
        <div class="word-book-tab-header word-book-header pl10">
          {{ checkedBookData.edition_name }}-{{ checkedBookData.grade_name }}
        </div>
        <div class="tab-container">
          <AllWord
            :unitList="unitList"
            :checkedBookData="checkedBookData"
            :initValue="value"
            ref="dictionTraining"
          ></AllWord>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Header from "@/components/Header";
import AllWord from "./allWord/Index";
import { getUnitList } from "@/api/index";

export default {
  data() {
    return {
      value: null,
      checkedBookData: null,
      unitList: [],
      activeName: "first",
    };
  },
  components: {
    Header,
    AllWord,
  },
  methods: {
    getUnitList() {
      let params = {
        bookId: this.checkedBookData.book_id,
      };
      getUnitList(params).then((res) => {
        if (res.code == 200 && res.data) {
          this.unitList = res.data;
          let checkedUnit = JSON.parse(localStorage.getItem("checkedUnit"));
          if (checkedUnit) {
            let data = this.unitList.filter((item) => {
              return item.unit_id == checkedUnit.unit_id;
            });
            if (data.length > 0) {
              this.value = checkedUnit.unit_id;
            }
          }
          //
          // 获取数据
        }
      });
    },
  },
  mounted() {},
  created() {
    this.checkedBookData = JSON.parse(localStorage.getItem("bookData"));
    if (this.$route.query.tab) {
      this.activeName = this.$route.query.tab;
    }
    this.getUnitList();
  },
};
</script>